import java.io.*;
import java.util.*;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;


public class XMLCreator {
	
	public static void marshal(List<Match> matches, File selectedFile) throws IOException, JAXBException {
		JAXBContext context;
		BufferedWriter writer = null;
		writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(selectedFile),"UTF-8"));
		context = JAXBContext.newInstance(Matches.class);
		Marshaller m = context.createMarshaller();
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		m.marshal(new Matches(matches), writer);
		writer.close();
	}
	public static List<Match> unmarshal(File importFile) throws JAXBException {
		
		Matches matches = new Matches();
		JAXBContext context = JAXBContext.newInstance(Matches.class);
		Unmarshaller um = context.createUnmarshaller();
		matches = (Matches) um.unmarshal(importFile);
	
		return matches.getMatches();
	}
}